package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.contracttemplate.LindiContractTemplateVO;
import com.minimalist.common.entity.lindi.vo.tradeapplicationtemplateconfirmletter.LindiTradeApplicationTemplateConfirmLetterQueryVO;
import com.minimalist.common.entity.lindi.vo.tradeapplicationtemplateconfirmletter.LindiTradeApplicationTemplateConfirmLetterVO;
import com.minimalist.common.feign.client.lindi.LindiTradeApplicationTemplateConfirmLetterFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 林地指标交易平台_交易申请确认函模板Feign客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author minimalist
 * @since 2024-12-19
 */
@Component
public class LindiTradeApplicationTemplateConfirmLetterFeignClientFallbackFactory extends BaseFallbackFactory<LindiTradeApplicationTemplateConfirmLetterFeignClient>{
    private static final Logger log = LoggerFactory.getLogger(LindiTradeApplicationTemplateConfirmLetterFeignClientFallbackFactory.class);


    @Override
    public LindiTradeApplicationTemplateConfirmLetterFeignClient create(Throwable cause){
        return new LindiTradeApplicationTemplateConfirmLetterFeignClient(){

            @Override
            public R<?> addTradeApplicationTemplateConfirmLetter(LindiTradeApplicationTemplateConfirmLetterVO tradeApplicationTemplateConfirmLetterVO){
                logServiceUnavailable("添加交易申请确认函模板", tradeApplicationTemplateConfirmLetterVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "添加交易申请确认函模板失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteTradeApplicationTemplateConfirmLetterByTradeApplicationTemplateConfirmLetterId(Long tradeApplicationTemplateConfirmLetterId){
                logServiceUnavailable("删除交易申请确认函模板", tradeApplicationTemplateConfirmLetterId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除交易申请确认函模板失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updateTradeApplicationTemplateConfirmLetterByTradeApplicationTemplateConfirmLetterId(LindiTradeApplicationTemplateConfirmLetterVO tradeApplicationTemplateConfirmLetterVO){
                logServiceUnavailable("修改交易申请确认函模板", tradeApplicationTemplateConfirmLetterVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "修改交易申请确认函模板失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiTradeApplicationTemplateConfirmLetterVO>> getPageTradeApplicationTemplateConfirmLetterList(LindiTradeApplicationTemplateConfirmLetterQueryVO queryVO){
                logServiceUnavailable("分页查询交易申请确认函模板列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "分页查询交易申请确认函模板列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiTradeApplicationTemplateConfirmLetterVO> getTradeApplicationTemplateConfirmLetterByTradeApplicationTemplateConfirmLetterId(Long tradeApplicationTemplateConfirmLetterId){
                logServiceUnavailable("获取交易申请确认函模板详情", tradeApplicationTemplateConfirmLetterId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "获取交易申请确认函模板详情失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteTradeApplicationTemplateConfirmLetterFileByFileId(Long fileId){
                logServiceUnavailable("删除交易申请确认函模板文件", fileId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除交易申请确认函模板文件失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<List<LindiContractTemplateVO>> getContractTemplateList(){
                logServiceUnavailable("获取合同模板列表", cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "获取合同模板列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> generateTemplateConfirmLetter(Long tradeApplicationId, Long confirmLetterTemplateId, String confirmLetterType, Long createId, Long tenantId){
                logServiceUnavailable("生成交易申请确认函模板", "tradeApplicationId: "
                        + tradeApplicationId + ", confirmLetterTemplateId: "
                        + confirmLetterTemplateId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "生成交易申请确认函模板失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}
